﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Web.Models.ProductGridModel>" %>

<%
    var isDescending = string.CompareOrdinal(Model.SortBy, ViewData["ColumnName"].ToString()) == 0 && Model.SortAscending;
    var routeData = new RouteValueDictionary { { "sortBy", ViewData["ColumnName"].ToString() }, { "ascending", !isDescending } };
    
    // Add in the querystring parameters *except* for the paging ones (as sorting should send us back to the first page of data)
    //routeData.AddQueryStringParameters().ExceptFor("page", "pageSize");ko can cai nay luon
    
    var htmlAttributes = new Dictionary<string, object>();
    if (string.CompareOrdinal(Model.SortBy, ViewData["ColumnName"].ToString()) == 0)
    {
        if (Model.SortAscending)
            htmlAttributes.Add("class", "sortAsc");
        else
            htmlAttributes.Add("class", "sortDesc");
    }
%>

<%: Html.ActionLink(
                        ViewData["DisplayName"].ToString(),                             // Link Text
                        Html.ViewContext.RouteData.Values["action"].ToString(),         // Action
                        Html.ViewContext.RouteData.Values["controller"].ToString(),     // Controller
                        routeData,                                                      // Route data
                        htmlAttributes                                                  // HTML attributes to apply to hyperlink
                   )
%>

